package cn.com.connected.base.params.page;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.Data;

/**
 * 分页参数
 * @author sms
 * @Date 2017-07-15
 */

@Data
public class PageParam implements java.io.Serializable {

	/**
	 * 
	 */
	public static final int DEFAULT_PAGE_SIZE = 20;
	
	/**
	 * 页号
	 */
	private int pageIndex;

	
	/**
	 * 每页显示条数
	 */
	private int pageSize;

	/**
	 * 加载多少条
	 */
	@ApiParam(hidden = true)
	@ApiModelProperty(notes = "加载多少条", hidden = true)
	private int totalCount;

	/**
	 * 分页起始行号
	 */
	@ApiParam(hidden = true)
	@ApiModelProperty(notes = "分页起始行号", hidden = true)
	private int offset;


	public PageParam() {
		this.pageIndex = 1;
		this.pageSize = DEFAULT_PAGE_SIZE;
	}

	public PageParam(int pageIndex,int pageSize) {
		pageIndex  = pageIndex<1?1:pageIndex;
//		pageIndex  = pageIndex>25?25:pageIndex;
		this.pageIndex = pageIndex;

		pageSize = pageSize>20?20:pageSize;

		//pageSize = -1 代表想要查所有 暂时给 它10000
		pageSize = pageSize==-1?10000:pageSize;

		pageSize = pageSize<1?1:pageSize;

		this.pageSize = pageSize;
	}

	public PageParam(int totalCount) {
		this.pageIndex = 1;
		this.pageSize = totalCount;
	}

	public int getOffset() {
		return (pageIndex>=1)?(pageIndex-1) * pageSize:0;
	}
}
